// 大厅数据处理

cc.Class({
    extends: cc.Component,

    properties: {
        m_name : cc.Label,
        m_id : cc.Label,
        m_score : cc.Label,
    },

    onLoad () {
        this.SetIcon('');

        this.SetName('啊啊aaaa');

        this.SetID('123654');

        this.SetScore('1123aa');
    },

    // 头像设置
    SetIcon : function(str) {
        var sprite = this.node.getChildByName("HomeBg").getChildByName("UpBG").getChildByName("Icon").getChildByName("Icon").getChildByName("icon").getComponent(cc.Sprite);
        var realUrl = cc.url.raw('resources/Communal/4.png');
        cc.loader.load(realUrl, function (err, texture) {
            var frame = new cc.SpriteFrame(texture);
            sprite.spriteFrame = frame;
            sprite.node.width = 150;
            sprite.node.height = 150;
        });
    },

    // 名字
    SetName : function(str) {
        if(str && str.length > 0) {
            var str1 = '';
            if(str.length > 4) {
                str1 = str.substr(0, 4);
                this.m_name.string = str1 + '...';
            } else {
                this.m_name.string = str;
            }
        } else {
            this.m_name.active = false;
        }
    },

    // ID
    SetID : function(id) {
        if(id && id.length > 0) {
            this.m_id.string = id;
        } else {
            this.m_id.active = false;
        }
    },

    // 分数
    SetScore : function(score) {
        if(parseInt(score) > 0) {
            this.m_score.string = parseInt(score);
        } else {
            this.m_score.string = '0';
        }
        
    },
});
